[mirrors]
http://www.musl-libc.org/releases/musl-1.1.12.tar.gz

[vars]
filesize=918757
sha512=7cabbe2665e32bd3408c8865f89f474106e982b4e5de81d0cdeea19e19e20b4d2496faf1adc6b2811d996f30f39258184ba347e8eb5f3811eab89179e8f52d70
desc='the C standard library (libc)'

[deps.host]
gcc4

[build]
patch -p1 < "$K"/musl-1.1.12-alignas.patch
./configure --prefix=$butch_prefix --syslibdir=$butch_prefix/lib
if [ "$A" = "powerpc" ] ; then
cat << EOF >> config.mak
LDFLAGS += -Wl,--secure-plt
CFLAGS += -msecure-plt
EOF
fi

# enable debug libc when DEBUGBUILD is set
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS += -O0 -g" >> config.mak
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS_ALL_SHARED += -O0 -g" >> config.mak

make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

[ "$butch_prefix" = "/" ] && butch_prefix=
dest=$butch_install_dir$butch_prefix
mkdir -p "$dest"/bin
ln -sf  ../lib/libc.so "$dest"/bin/ldd

musl_gcc="$dest/bin/musl-gcc"

cp "$K/musl-gcc" "$musl_gcc"
chmod +x "$musl_gcc"
sed -i "s,AAAA,$A," "$musl_gcc"
sed -i "s,PPPP,$butch_prefix," "$musl_gcc"

#create dynlinker path file which only contains /lib
#this should speed up dynamic linker path search
mkdir -p "$dest"/etc
printf "%s\n" "$butch_prefix"/lib > "$dest"/etc/ld-musl-$A.path
